home *** CD-ROM | disk | FTP | other *** search
- Path: crl.crl.com!not-for-mail
- From: bobfry@crl.com (Robert Fry)
- Newsgroups: comp.lang.c
- Subject: Re: performance of fread
- Date: 26 Jan 1996 08:22:35 -0800
- Organization: CRL Dialup Internet Access
- Message-ID: <4eav4b$ln7@crl.crl.com>
- References: <4eaecp$m5a@zeus.rbi.informatik.uni-frankfurt.de>
- NNTP-Posting-Host: crl.com
-
- Ferber@zoology.uni-frankfurt.de (Michael Ferber) writes:
-
- <description of problem snipped to conserve bandwidth>
-
- >I think there are several ways to do this.
- >1. To read each integer and put it into the appropriate array, and the read
- > the next value. This assumes that I have call fread d * n times. Due to the
- > fact that I have to read many (several thousand) integers this seems to be
- > slow but easy to implement.
- >2. To read many integers into a buffer. And then copy the integers to their
- > appropriate arrays. This seems to be faster, but more difficult to control
- > compared with 3 and 1, because I always have to check if a new read is
- > necessary while processing the data within the array.
- >3. To use the approach described in 1. but with a large buffer set with
- > setvbuf.
- >Furthermore I cannot read all the data of the file in a single turn because a
- >single file may contain a theoretically unlimited number of integers, usually
- >my files contain about 12 - 15 million points.
-
- All three of these methods should work. However, from my own background
- (image processing), method #2 has been the most common choice.
-
- >My question: How time consuming is the overhead of calling fread reading from
- >a large buffer compared to a for( ) loop which takes his data from a memory
- >block which was filled by a single call of fread.
-
- This is the reason method #2 has been the usual choice: the answer to
- your question is extremely implementation-dependent. The only way to get
- an answer for your setup is to either test it yourself or query the
- manufacturer. In my own experience, the use of many fread's is measurably
- slower than a tight loop you might write for yourself, but whether that
- difference is enough for you to want to make the extra effort is
- something you need to decide for your situation.
-
- Bob
-